package org.jeecg.modules.gis.util.mybatis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class GisDialectRegistry {

    private final Map<String, GisDialect> dialectMap = new HashMap<>();

    @Autowired
    public GisDialectRegistry(List<GisDialect> dialectList) {
        for (GisDialect dialect : dialectList) {
            dialectMap.put(dialect.supportDbType().toLowerCase(), dialect);
        }
    }

    public GisDialect getDialect(String dbType) {
        GisDialect dialect = dialectMap.get(dbType.toLowerCase());
        if (dialect == null) {
            throw new UnsupportedOperationException("未支持的数据库类型: " + dbType);
        }
        return dialect;
    }
}
